# coding: utf-8

'''
author: runforever
'''

from django.test import TestCase

from .models import OpLog
from .utils import oplog_utils


class TestOpLogUtils(TestCase):

    def setUp(self):
        self.oplog = OpLog.objects.create(
            object_id=12346,
            object_type='market',
            log='test',
            operator='test operator',
        )

    def tearDown(self):
        self.oplog.delete()

    def test_model_instance_diff(self):
        diff = oplog_utils.model_instance_diff(self.oplog, self.oplog)
        self.assertEqual(diff, None)

        diff = oplog_utils.model_instance_diff(None, self.oplog)
        self.assertTrue(diff)

        diff = oplog_utils.model_instance_diff(self.oplog, None)
        self.assertTrue(diff)

        change_oplog = OpLog.objects.filter(id=self.oplog.id).first()
        change_oplog.log = 'change'
        diff = oplog_utils.model_instance_diff(self.oplog, change_oplog)
        self.assertTrue(diff)
